package com.ehome.poct.backend.util;

import java.text.DecimalFormat;

public class ByteSizeUtil {
    /**
     * 字节转kb/mb/gb
     * @param size
     * @return
     */
    public static  String getSize(Integer size) {
        if(size<=0) return "0";
        final String[] units = new String[]{"B","KB","MB","GB"};
        int digitGroups = (int)(Math.log10(size)/Math.log10(1024));
        return new DecimalFormat("#,##0.###").format(size/Math.pow(1024,digitGroups)) +units[digitGroups];
    }
}
